package leetcode;

/**
 * @author:xufengxiang
 * @date 2023-05-09 20:23
 */
public class Code26 {
    public static int removeDuplicates(int[] nums) {
        int length = nums.length;
        int removeLength = 0;
        int preNum = nums[0];
        for(int i=1;i< nums.length;i++){
            if(nums[i] == preNum){
                removeLength++;
                //nums[i] =0;
            }else{
                nums[i-removeLength] = nums[i];
                preNum = nums[i];
                //nums[i]=0;
            }
        }
        return length - removeLength;
    }


    public static void main(String[] args) {
        int[] nums = new int[]{0,0,1,1,1,2,2,3,3,4};

        removeDuplicates(nums);
        for (int i:nums){
            System.out.println(i);

        }
        System.out.println(nums);
    }


}
